/*
 * @Author       : Hejh(3010733382@qq.com)
 * @Version      : V1.0
 * @Date         : 2024-02-03 20:22:47
 * @Description  : 用于获取当前用户的permission列表，根据permission生成左侧菜单
 */

import { getUserPermissions } from '@/api/user'
import type { IndexObj } from '@/types/commom'
import { adminMenu, filterAdminMenu } from '@/views/Admin/config/index'

export const usePermission = () => {
  const newMenu = ref<IndexObj[]>([])
  const loadSuc = ref(false)
  const getNewMenu = async () => {
    await getUserPermissions()
      .then((res) => {
        newMenu.value = filterAdminMenu(res.data, adminMenu)
        loadSuc.value = true
      })
      .catch(console.error)
  }

  return {
    newMenu,
    getNewMenu,
    loadSuc
  }
}
